/****************************************************************************
  ECE 486 Project 1
  PDP-8 Simulator

  opcode7group2.cpp

  Group 2 microinstructions including OR subgroup and AND subgroup
****************************************************************************/

#include "header.h"

//skip next instruction if AC < 0
int SMA (unsigned short inst)
{
	if ((LB_AC & 004000))
	{
		PC++;
	}
	return 0;
}

//skip next instruction if AC is 0
int SZA(unsigned short inst)
{
	if ((LB_AC & 007777) == 000000)
	{
		PC++;
	}
	return 0;
}

//skip next instruction if LB != 0 (LB == 1)
int SNL (unsigned short inst)
{
	if ((LB_AC & 010000) == 010000)
	{
		PC++;
	}
	return 0;

}

int SMASZA(unsigned short inst) //skip if AC < 0 OR LB_AC = 0
{
	if ((LB_AC & 004000) || !(LB_AC & 007777))
		++PC;

	return 0;
}

int SMASNL(unsigned short inst) //skip if AC < 0 OR LB != 0
{
	if ((LB_AC & 004000) || (LB_AC & 010000))
		++PC;

	return 0;
}

int SZASNL(unsigned short inst) //skip if AC = 0 OR LB! = 0
{
if (!(LB_AC & 007777) || (LB_AC & 010000))
		++PC;

	return 0;
}

int SMASZASNL(unsigned short inst) //skip if AC <= 0 OR LB != 0
{
	if ((LB_AC & 004000) || !(LB_AC & 007777) || (LB_AC & 010000))
		++PC;

	return 0;
}


//AND GROUP
//skip next instruction if LB_AC is positive
int SPA(unsigned short inst)
{
	if ((LB_AC & 004000) == 00000)
		{
			++PC;
		}
	return 0;
}

//skip next instruction if LB_AC is nonzero 
int SNA(unsigned short inst)	
{
	if ((LB_AC & 007777) != 00000)
	{
		PC++;
	}
	return 0;
}

//skip next instruction if L is zero
int SZL(unsigned short inst)	
{
	if ((LB_AC & 010000) == 000000)
	{
		PC++;
	}
	return 0;
}

//skip next instruction if LB_AC is positive and nonzero
int SPASNA(unsigned short inst)
{
	if (((LB_AC & 004000) == 00000) && (LB_AC & 007777))
	{
		++PC;
	}
	return 0;

}
//skip next instruction if AC!=0 and LB=0
int SNASZL(unsigned short inst)
{
	if ((LB_AC & 007777) && !(LB_AC & 010000))
		PC++;

	return 0;
}
//skip next instruction if AC>=0 and LB=0
int SPASZL(unsigned short inst)
{
	if (!(LB_AC & 004000) && !(LB_AC & 010000))
		PC++;

	return 0;
}
//skip next instruction if AC is nonzero positive and LB is zero
int SPASNASZL(unsigned short inst)
{
	if (!(LB_AC & 004000) && (LB_AC & 007777) && !(LB_AC & 010000))
		++PC;

	return 0;
}

//skip next instruction unconditionally
int SKP(unsigned short inst)	
{
	PC++;
	return 0;
}

//clear LB_AC - redundant definition
//int CLA(unsigned short inst)
//{
//	LB_AC &= 010000;
//	return 0;
//}

//or SR with LB_AC
int OSR(unsigned short inst)
{
	LB_AC |= (SR & 007777); 
	return 0;
}

//halt  (no-op)
int HLT(unsigned short inst)		
{
	return 0;
}